//
//  TopicViewController.m
//  MJApp
//
//  Created by wangliang on 15/7/5.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "TopicViewController.h"

#import "TopicView.h"
#import "TopicTableViewCell.h"

@interface TopicViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation TopicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self NaviUI];
    [self UI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)NaviUI {
    
    self.leftBtn.hidden = YES;
    TopicView *topicView = [[TopicView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 44)];
    self.navigationItem.titleView = topicView;
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.frame) - 80, 0, 80, 44)];
    [button setTitle:@"取消" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [topicView addSubview:button];
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(10, 5, CGRectGetWidth(self.view.frame) - 10 - CGRectGetWidth(button.frame), 34)];
    backView.backgroundColor = [UIColor whiteColor];
    backView.layer.cornerRadius = 2;
    [topicView addSubview:backView];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"huati_Search"]];
    [backView addSubview:imageView];
    imageView.center = CGPointMake(imageView.center.x + 5, CGRectGetHeight(backView.frame) / 2);
    
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(imageView.frame) + 5, 0, CGRectGetWidth(backView.frame) - CGRectGetWidth(imageView.frame) - 10, CGRectGetHeight(backView.frame))];
    textField.placeholder = @"话题";
    textField.tintColor = [UIColor grayColor];
    [backView addSubview:textField];
}



- (void)clickRightButton {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)UI {
    
    CGRect frame = self.view.bounds;
    frame.size.height -= 64;
    frame.origin.x = 5;
    frame.size.width -= 10;
    UITableView *tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    tableView.backgroundColor = Color_Back_Gray;
    self.view.backgroundColor = Color_Back_Gray;

}

- (void)obationData {

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellID = @"TopicTableViewCell";
    TopicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        
        cell = WL_XIB(@"TopicTableViewCell");
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 0.1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 35;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.frame), 35)];
    view.backgroundColor = Color_Back_Gray;
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 35)];
    if (section == 0) {
        label.text = @"最近使用";
    }else {
        label.text = @"热门话题";
    }
    
    label.textColor = RGB(142, 141, 147);
    label.font = [UIFont systemFontOfSize:15];
    [view addSubview:label];
    return view;
}

@end
